Skip to content

Refactor tests of xc module#7475

Merged
mohanchen merged 5 commits into
deepmodeling:developfrom
mohanchen:20260616-2
Jun 22, 2026
Merged

Refactor tests of xc module#7475
mohanchen merged 5 commits into
deepmodeling:developfrom
mohanchen:20260616-2

Conversation

@mohanchen

Copy link
Copy Markdown
Collaborator

No description provided.

abacus_fixer added 2 commits June 16, 2026 22:28
This commit decouples XC_Functional and related libxc functions from the global PARAM object by adding explicit parameters:

1. Modified XC_Functional::v_xc() to accept nspin, domag, domag_z parameters instead of accessing PARAM
2. Modified XC_Functional::gradcorr() to accept nspin, domag, domag_z parameters
3. Modified XC_Functional::set_xc_type() to accept nspin parameter
4. Modified XC_Functional_Libxc::v_xc_libxc() to accept nspin, domag, domag_z parameters
5. Modified XC_Functional_Libxc::v_xc_meta() to accept nspin parameter

Updated all call sites in:
- source_estate/module_pot/pot_xc.cpp
- source_estate/module_pot/pot_xc_fdm.cpp
- source_pw/module_pwdft/forces_cc.cpp
- source_pw/module_pwdft/stress_cc.cpp
- source_hamilt/module_xc/xc_pot.cpp
- source_hamilt/module_xc/libxc_pot.cpp
- source_hamilt/module_xc/libxc_abacus.h

Updated test files to remove PARAM dependencies:
- test_xc3.cpp: Removed PARAM include and initialization
- test_xc5.cpp: Removed PARAM include and initialization, updated v_xc, v_xc_meta calls
- xctest.h: Removed PARAM include and initialization

Default parameter values are provided for backward compatibility.
@mohanchen mohanchen added Refactor Refactor ABACUS codes Tests/Examples Issues/PR related to unit tests and integrate tests The Absolute Zero Reduce the "entropy" of the code to 0 labels Jun 17, 2026
abacus_fixer added 2 commits June 17, 2026 09:04
…prove parameter passing

Summary of changes:

1. Modified libxc_abacus.h:
   - Removed default value (=1) for nspin parameter in v_xc_libxc
   - Removed default value (=nullptr) for scaling_factor parameter in v_xc_libxc

2. Modified xc_functional.h:
   - Changed set_xc_type signature to only accept const std::string xc_func_in
   - Removed nspin and basis_type parameters from set_xc_type
   - Removed default parameters from v_xc and gradcorr

3. Modified xc_functional.cpp:
   - Updated set_xc_type implementation to match new signature
   - Removed meta-GGA nspin=4 check from set_xc_type (moved to gradcorr)
   - Removed hybrid functional LCAO check from set_xc_type (no longer needed)
   - Updated internal set_xc_type calls to use single parameter

4. Modified xc_grad.cpp:
   - Added meta-GGA nspin=4 check at the beginning of gradcorr function
   - This is the correct place for runtime validation since nspin is known here

5. Modified xc_pot.cpp:
   - Updated v_xc_libxc call to pass parameters correctly

6. Modified libxc_pot.cpp:
   - Updated v_xc_libxc implementation to match new signature

7. Modified stress_gga.cpp:
   - Changed direct 'true' argument to named variable 'is_stress' for gradcorr call
   - Improved code readability and maintainability

8. Updated all set_xc_type call sites (12 files):
   - test_xc.cpp, test_xc1.cpp, test_xc2.cpp, test_xc3.cpp, test_xc5.cpp
   - xc_functional.cpp, esolver_double_xc.cpp, esolver_ks_lcaopw.cpp
   - esolver_fp.cpp, Exx_LRI_interface.hpp, xc_kernel.cpp, exx_helper.cpp
   - All calls now pass only the xc_func_in parameter

9. Updated test_xc3.cpp and test_xc5.cpp:
   - Added named variables (nspin1, nspin2, nspin4, domag, domag_z, domag_true)
   - Removed direct numeric literals in function calls

Rationale:
- Separated functional setup (set_xc_type) from runtime configuration (nspin, basis_type)
- Runtime validation checks moved to actual computation functions (gradcorr)
- Parameter passing improved with meaningful variable names instead of magic numbers
- Code readability and maintainability enhanced
- Preparation for future improvements to XC functional interface

@zzlinpku zzlinpku left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review: Refactor tests of xc module

This PR decouples v_xc, v_xc_libxc, v_xc_meta, and gradcorr from the global PARAM singleton by passing nspin, domag, domag_z as explicit parameters. This is a solid testability improvement — the #define private public hack is removed and tests no longer mutate global state.

However, two safety checks were removed/moved as side effects, which warrants attention.

See inline comments for details.

Comment thread source/source_hamilt/module_xc/xc_functional.cpp
Comment thread source/source_hamilt/module_xc/xc_functional.cpp
Comment thread source/source_hamilt/module_xc/libxc_abacus.h
Comment thread source/source_hamilt/module_xc/test/xctest.h
Comment thread source/source_hamilt/module_xc/xc_grad.cpp
Comment thread source/source_pw/module_pwdft/stress_gga.cpp Outdated

@zzlinpku zzlinpku left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-reviewed after updates. The multi-line reformatting in stress_gga.cpp looks good — thanks for addressing that. The design choices (meta-GGA check in gradcorr, link-time __EXX guard) are reasonable. LGTM.

Comment thread source/source_hamilt/module_xc/xc_grad.cpp
Comment thread source/source_pw/module_pwdft/stress_gga.cpp
@mohanchen mohanchen merged commit 9839f9c into deepmodeling:develop Jun 22, 2026
14 checks passed
maki49 added a commit to maki49/abacus-develop that referenced this pull request Jun 22, 2026
maki49 added a commit to maki49/abacus-develop that referenced this pull request Jul 6, 2026
PeizeLin pushed a commit that referenced this pull request Jul 6, 2026
* initial version of writing H and dH terms (except exx)

* correct 1-electron terms: T, Vl, Vnl

* fix pot register

* Gint_drho

* add EXX H&dH, dH (H-F term) of Veff Hartree, and refactor

* add dm_container_to_Ds and exx nscf-from-dm workflow; minor refactor OperatorEXX

* fix parallel segfaults and kinetic sign

* XC H-F term (FD)

* enable value-adding HContainers, total dH and atom-specified output; enable nspin=2

* dH test cases

* exclude cal_exx_dHs with __EXX_DEV flag, waiting for LibRI PR merged

* small fixes

* change scf_in_dmr ref due to not renormalizing charge at init_chg==dm

* fix conflict #7462 #7475 #7478

* Revert reference change by adding option dm_no_renormalize to init_chg

This reverts commit ed14d9f.

* fix pyabacus CI
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Refactor Refactor ABACUS codes Tests/Examples Issues/PR related to unit tests and integrate tests The Absolute Zero Reduce the "entropy" of the code to 0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants